package work.linruchang.mybatisplussamplestest.config.mybatisplus.injector;

import com.baomidou.mybatisplus.core.enums.SqlMethod;
import com.baomidou.mybatisplus.core.injector.AbstractMethod;
import com.baomidou.mybatisplus.core.injector.methods.DeleteById;
import com.baomidou.mybatisplus.core.metadata.TableInfo;
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.mapping.SqlSource;

/**
 * 作用：物理删除
 *  照抄{@link DeleteById}
 * @author LinRuChang
 * @version 1.0
 * @date 2022/06/14
 * @since 1.8
 **/
public class DeleteByIdPhysical extends AbstractMethod {
    @Override
    public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {
        String sql;
        SqlMethod sqlMethod  = SqlMethod.DELETE_BY_ID;
        sql = String.format(sqlMethod.getSql(), tableInfo.getTableName(), tableInfo.getKeyColumn(),
                tableInfo.getKeyProperty());
        SqlSource sqlSource = languageDriver.createSqlSource(configuration, sql, Object.class);
        //return this.addDeleteMappedStatement(mapperClass, getMethod(sqlMethod), sqlSource);
        return this.addDeleteMappedStatement(mapperClass, "deleteByIdPhysical", sqlSource);
    }
}
